package com.nettylern.netty.msgpack编解码;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;

/**
 * @author liliang
 * @date 2019/12/5.
 */
public class MsgPackEncoder extends MessageToByteEncoder<Object> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Object object, ByteBuf byteBuf) throws Exception {

        MessagePack pack = new MessagePack();
        byte[] bytes = pack.write(object);
        byteBuf.writeBytes(bytes);

    }
}
